/*
** test initralize 
*/
#include <stdio.h>
#include <string.h>

static char * lcs_logname = "lcs_initralize";
static char lcs_logbuf[512];
static void lcs_testlog()
{
	int fp;
	
	fp = fopen( lcs_logname, "at" );
	if( !fp ) return;

	printf( "%s", lcs_logbuf );
	fprintf( fp, "%s", lcs_logbuf );
	
	fclose( fp );
}

/*
** test begin...
*/

int ini_array()
{
	int i, j, total=0;
	static unsigned char s1[4][16] = {
		14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
		0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
		4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
		15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 };

	static unsigned char s2[4][16] = {
		15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
		3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
		0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
		13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 };

	char s[100] = "zhongguo shi shufa de haiyang !";

	for( i=0; i<4; i++ ){
		for( j=0; j<16; j++ )
			total += s1[i][j];
	}
	
	for( i=0; i<4; i++ ){
		for( j=0; j<16; j++ )
			total += s2[i][j];
	}

	sprintf( lcs_logbuf, "%d\n", total );
	lcs_testlog();

	sprintf( lcs_logbuf, "%s\n", s );
	lcs_testlog();

	return total;
}

int ini_const()
{
	int a = 123ul;
	int b = 0123456;
	int c = 0x12;
	int d = 0xFF;
	double e = 0.12f;
	double f = 012.34;
	double g = 2e2;
	double h = 2e+2;
	double i = 2e-2;
	double j = 2.1E2;
	double k = 2.123E+7;
	double l = 2.1234E-2;
	
	sprintf( lcs_logbuf, "%d %d %d %d \n%f %f %f %f \n%f %f %f %f \n%f\n",
		a, b, c, d, 
		e, f, g, h, 
		i, j, k, l,
		a+b+c+d+e+f+g+h+i+j+k+l );
	lcs_testlog();
	
	return 0;
}

int ini_struct()
{
	struct _st{
		char c;
		short s;
		int i;
		long l;
		unsigned char uc;
		unsigned short us;
		unsigned int ui;
		unsigned long ul;
		float f;
		double d;
		char ac[100];
		unsigned char uac[100];
	}s[3]={
		{ 'a', 1, 2, 3, 'i', 10, 11, 12, 1.2, 3.4, "hello world 1", "hello world 4", },
		'b', 4, 5, 6, 'j', 14, 15, 16, 1.5, 3.6, "hello world 2", "hello world 5",
		'c', 7, 8, 9, 'k', 17, 18, 19, 1.7, 3.8, "hello world 3", "hello world 6",
	};
	int i;
	for( i=0; i<3; i++ ){
		sprintf( lcs_logbuf, "%c, %d, %d, %d, %c, %d, %d, %d, %f, %f, %s, %s\n", 
			s[i].c, s[i].s, s[i].i, s[i].l, s[i].uc, s[i].us, s[i].ui, s[i].ul, s[i].f, s[i].d, s[i].ac, s[i].uac );
		lcs_testlog();
	}
	return 0;
}

int lcs_initralize()
{
	ini_array();
	ini_const();
	ini_struct();
	return 0;
}

